const { ccclass, property } = cc._decorator;

@ccclass
export default class extends cc.Component {
    @property({ type: cc.AudioClip, displayName: CC_DEV && '缩放音效' })
    scaleEffect: cc.AudioClip = new cc.AudioClip();
    heroNode: cc.Node = null;
    start() {
        this.heroNode = this.node.getChildByName('Hero');
        this.heroNode.getComponent(cc.Animation)['heroScaled'] = () => {
            cc.audioEngine.playEffect(this.scaleEffect, false);
        }
        this.node.on(cc.Node.EventType.TOUCH_START, this.heroMove, this);
        this.node.on(cc.Node.EventType.TOUCH_MOVE, this.heroMove, this);
    }

    private heroMove(event: cc.Event.EventTouch) {
        let pos = this.heroNode.parent.convertToNodeSpaceAR(event.getLocation());
        this.heroNode.x = pos.x;
        this.heroNode.y = pos.y;
    }
}
